<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="css/bootstrap.css">
    <script src="js/jquery-3.6.1.js"></script>
    <script src="js/bootstrap.js"></script>
</head>
<body>

<div class="container">
    <div class="panel panel-default">
        <div class="panel-heading">

            <h2>生日格式数据类型转换（例如生日必须填写成yyyy-MM-dd）</h2>

        </div>
        <div class="panel-body">

            <form class="form-horizontal">
                <div class="form-group">
                    <label for="t1" class="col-sm-2 control-label">用户名</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" id="t1" placeholder="填写用户名">
                    </div>
                </div>
                <div class="form-group">
                    <label for="t2" class="col-sm-2 control-label">生日</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" id="t2" placeholder="填写生日">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="button" id="b1" class="btn btn-default">提交</button>
                    </div>
                </div>
            </form>

        </div>
    </div>
    <hr>
    <div class="panel panel-default">
        <div class="panel-body">
            <h4>生日结果：<span id="s1">aaa</span></h4>
        </div>
    </div>


</div>


</body>
</html>

<script>

    $(function () {
        $("#b1").click(function () {

            $.ajax(
                {
                    url: "/get.action",
                    //默认是get请求
                    type: "post",
                    //后端返回数据的格式JSON
                    dataType: "json",
                    data: {
                        name: $("#t1").val(),
                        age:$("#t2").val()
                    },
                    //请求之前做的事情
                    beforeSend: function (XMLHttpRequest) {
                        console.log("请求之前做的事情。。。。。。。。。。。")
                    },
                    //请求成功返回这里
                    success: function (data, textStatus, jqXHR) {
                        console.log("请求成功。。。。。。。。。。。");



                        if(data.result=="success"){
                            $("#s1").text(data.data.age);
                        }
                        else{
                            $("#s1").text(data.error);
                        }




                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.log("请求错误。。。。。。。。。。。")
                    },
                    //请求完毕后调用
                    complete: function (XMLHttpRequest, textStatus) {
                        console.log("请求完毕。。。。。。。。。。。")
                    }
                }
            );
        });


    });


</script>